<?php
/**
 * @Author: lianlianzan(13040@qq.com)
 * @Date:   2018-08-18 16:40:16
 * @Last Modified by:   zhaozilong
 * @Last Modified time: 2018-11-24 08:45:44
 */

namespace app\home\controller;
use app\common\controller\Base;
use app\admin\logic\AdminUser as AdminUserLogic;
use think\Loader;

class HomeBase extends Base {

	function initialize() {
		parent::initialize();
		
		// 系统开关
		if (!config('system.toggle_web_site')) {
			$this->error('站点已经关闭，请稍后访问~');
		}
		
		$adminuid = AdminUserLogic::isLogin();
		$this->assign('adminuid', $adminuid);

		if ($adminuid) {
			$adminUserDao = model('admin/AdminUser');
			$admindb = $adminUserDao->getInfo($adminuid);
			$this->assign('admindb', $admindb);
		}
	}
	
	function _initialize000() {
		parent::initialize();
		
		include UC_CLIENT_ROOT."config.inc.php";

		$winduid = 0;

		$list = explode("\t", addslashes(_authcode(cookie('user_login_auth'))));
		if (count($list) > 1) {
			list($winduid, $windpwd) = $list;
		}

		if ($winduid) {
			$userModel = model('common/User');
			$winddb = $userModel->getInfo($winduid);
			//print_r($winddb);

			$this->winduid = $winduid;
			$this->windname = $winddb['username'];
			$this->winddb = $winddb;

			$this->assign('winduid', $winduid);
			$this->assign('windname', $winddb['username']);
			$this->assign('winddb', $winddb);

			$this->onlineip = get_client_ip();
			if (in_array($this->winddb['groupid'], array(3, 4, 46))) { //管理员编辑的情况
				$this->isManage = 1;
				$this->assign('isManage', $this->isManage);
			}
		} else {
			$this->assign('winduid', 0);
			$this->assign('windid', '');
		}
		//$this->currentUser = cookie('user_login_auth');
		//print_r($this->currentUser);

		//$this->assign('current_user', $this->currentUser);
		
		//主题的公共资源目录
		$theme_public_path = THEME_PATH.'home/';
		$this->assign('header_menus',logic('Nav')->getNavigationMenus('header'));
		$this->assign('_theme_public_', $theme_public_path); // 页面公共继承模版
		$this->assign('_theme_public_layout', $theme_public_path.'layout.html'); // 页面公共继承模版
	}

	/**
	 * 验证数据
	 * @param  string $validate 验证器名或者验证规则数组
	 * @param  array  $data			 [description]
	 * @return [type]				 [description]
	 */
	public function validateData($data,$validate)
	{
		if (!$validate || empty($data)) return false;
		$result = $this->validate($data,$validate);
		if(true !== $result){
			// 验证失败 输出错误信息
			$this->error($result);exit;
		}
		return true;

	}

	/**
	 * 页面配置信息
	 * @param  string $title  标题
	 * @param  string $main_mark [description]
	 * @param  string $mark	  [description]
	 * @return [type]		  [description]
	 */
	public function pageInfo($title='',$mark='',$extend=[])
	{
		$page_config = [
			'title'	 => $title,
			'mark'	 => $mark
		];
		if(!empty($extend) && is_array($extend)) $page_config = array_merge($page_config,$extend);

		//添加面包屑导航数据
		$page_config['breadcrumbs'] = $this->breadCrumbs($page_config);
		$this->assign('page_config',$page_config);
	}

	/**
	 * 面包屑导航
	 * @param  array  $page_config [description]
	 * @return [type]			   [description]
	 */
	protected function breadCrumbs($page_config = [])
	{
		$crumbs = '';
		if (!empty($page_config['crumb_parent_title'])) {
			$crumbs.='<li><a href="'.$this->url.'">'.$page_config['crumb_parent_title'].'</a></li>';
		} else{
			$module_info = db('modules')->where(['name'=>MODULE_NAME])->field('title')->find();
			$crumbs.='<li><a href="'.$this->url.'">'.$module_info['title'].'</a></li>';
		}
		$crumbs.='<li class="active">'.$page_config['title'].'</li>';

		return '<li><a href="'.url('home/index/index').'"><i class="fa fa-dashboard"></i> 首页</a></li>'.$crumbs;
	}
}
